package com.example.photography.adapter.store;

import android.content.Context;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.StoreHomeBean;
import com.example.photography.util.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ChannelAdapter extends MyBaseAdapter {
    public ChannelAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_channel, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        StoreHomeBean.ResultBean.ChannelInfoBean channelInfoBean = (StoreHomeBean.ResultBean.ChannelInfoBean) list.get(position);
        Glide.with(UIUtils.getContext())
                .load(channelInfoBean.getImage())
                .thumbnail(Glide.with(UIUtils.getContext()).load(R.drawable.loading))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(viewHolder.ivChannel);
        viewHolder.tvChannel.setText(channelInfoBean.getChannel_name());
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.iv_channel)
        ImageView ivChannel;
        @BindView(R.id.tv_channel)
        TextView tvChannel;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
